from tortoise import fields, models

class EnvParameter(models.Model):
    env_param_id = fields.IntField(pk=True)
    battery = fields.ForeignKeyField('models.Battery', related_name='env_parameters', on_delete=fields.CASCADE)

    granularity = fields.IntField(description="划分粒度")
    period = fields.IntField(description="划分周期")
    period_unit = fields.CharField(max_length=20, description="划分周期单位")
    initial_capacity = fields.FloatField(description="电池初始容量")
    name = fields.CharField(max_length=20, description="环境参数名称")

    parameters = fields.ManyToManyField(
        'models.Parameter',
        through='env_param_parameter',
        related_name='env_parameters'
    )

    prices = fields.ManyToManyField(
        'models.ElectricPriceInfo',
        through='env_param_price',
        related_name='env_parameters'
    )

    class Meta:
        table = "env_parameter"

    def __str__(self):
        return f"EnvParameter {self.env_param_id}"